/**
 * main.c
 *
 * 	Created on: 2012-3-8
 *      Author: tianmax
 *
 * 	功能：main函数所在文件，对wk_list做测试
 */

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "wk_slist.h"
#include "wk_vector.h"
#include "wk_hash.h"

void* print_int(WPElement e,void* ctx){
	static int i=0;
	if(e!=NULL){
		printf("element %d ,value=%d\n",i,(int)*(int*)e);
	}
	i++;

	return NULL;
}
void* comp(WPElement e,void* ctx){
	if(e==NULL || ctx==NULL){
		return NULL;
	}
	if(*(int*)e==*(int*)ctx){
		return (void*)e;
	}else{
		return (void*)0;
	}
}
/**
 * 遍历元素相关
 * ctx上下文
 */
extern void* iterate_test(WSList* list,wk_element_iterate_do iterate_do,void* ctx){
	/**
	 * 参数检查
	 */
	if(list==NULL){
		return NULL;
	}
	void* retp=NULL;
	wk_slist_begin(list);
	while(list->current!=NULL){
		retp=iterate_do(list->current->e,ctx);
		if(retp!=(void*)0){
			break;
		}
		list->current=list->current->next;
	}
	return list->current;
}
void* print_str(WPElement e,void* ctx){
	printf("====value=%s\n",(char*)e);

	return NULL;
}
int main(int argc,char** argv){

//	WVector* vector=wk_vector_init(5,6);
//
//	wk_vector_insert(vector,0,strdup("hello"));
//
//	wk_vector_insert(vector,7,strdup("world"));
//
//	wk_vector_insert(vector,-1,strdup("tianmax1"));
//
//	wk_vector_insert(vector,-1,strdup("tianmax2"));
//
//	wk_vector_insert(vector,-1,strdup("tianmax3"));
//
//	wk_vector_append(vector,strdup("tianmax4"));
//	wk_vector_append(vector,strdup("tianmax5"));
//	wk_vector_append(vector,strdup("tianmax7"));
//	wk_vector_append(vector,strdup("tianmax8"));
//	wk_vector_append(vector,strdup("tianmax9"));
//	wk_vector_append(vector,strdup("tianmax10"));
//
//	//wk_vector_clear(vector);
//
//	wk_vector_removeFirst(vector);
//	wk_vector_removeLast(vector);
//
//
////	int i;
////	for(i=0;i<wk_vector_count(vector);i++){
////	printf("====element %d ,value=%s\n",i,(char*)wk_vector_value(vector,i));
////	}
//	printf("=================================\n");
//
//	wk_vector_iterate(vector,print_str,NULL);
//
//	wk_vector_trim2count(vector);
//
//	printf("count=%d\n",vector->count);
//	printf("size=%d\n",vector->size);
//
//	wk_vector_destroy(vector);

	WHash* hash=wk_hash_init(20,NULL,NULL);

	printf("%p\n",hash);

	wk_hash_destroy(hash);
	hash=NULL;


	return 0;
}
